home *** CD-ROM | disk | FTP | other *** search
- Path: dawn.mmm.com!news
- From: kjhopps@mmm.com (Kevin J Hopps)
- Newsgroups: comp.lang.c++
- Subject: Re: Strongly Typed Function Pointers
- Date: 25 Jan 1996 14:41:33 GMT
- Organization: 3M - St. Paul, MN 55144-1000 US
- Message-ID: <4e84qt$74u@dawn.mmm.com>
- References: <erik-2401961956090001@annex-dialup02.med.cornell.edu>
- Reply-To: kjhopps@mmm.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Erik A. Dahl (erik@mail.med.cornell.edu) wrote:
- > I have a program that I'm porting from C to C++ which uses void (*)(void*)
- > function pointers to call many differant "types" of functions (ones with
- > differant argument lists). This of course works in C but I'm dying in C++
- > with compiler errors (becuase the pointer isn't of the right type). Is
- > there an easy way around this problem??
-
- You might be able to get away with casting the function pointer to a
- different type of function pointer and calling throught the result. But
- this is not guaranteed to work. From the April working paper:
- A pointer to a function can be explicitly converted to a pointer to a
- function of a different type. The effect of calling a function
- through a pointer to a function type that differs from the type used
- in the definition of the function is undefined. Except that convert-
- ing an rvalue of type "pointer to T1" to the type "pointer to T2"
- (where T1 and T2 are function types) and back to its original type
- yields the original pointer value, the result of such a pointer con-
- version is unspecified.
- --
- Kevin J. Hopps e-mail: kjhopps@mmm.com
- 3M Company phone: (612) 737-4643
- 3M Center, Bldg. 235-2D-57 fax: (612) 737-2700
- St. Paul, MN 55144-1000 Opinions are my own. I don't speak for 3M.
- But 3M speaks for me -- I did not write the following line:
-
- Opinions expressed herein are my own and may not represent those of 3M.
-